package org.joyflow.core.common;

import com.alibaba.fastjson.JSONObject;

public class R extends JSONObject {
    private static final String CODE_TAG = "code";
    private static final String DATA_TAG = "data";
    private static final String MSG_TAG = "msg";

    public static final int SUCCESS = 200;
    public static final int FAILED = 500;

    public static R success(Object data) {
        return new R().setCode(SUCCESS).setData(data).setMsg("成功");
    }

    public static R success() {
        return new R().setCode(SUCCESS).setMsg("成功");
    }

    public static R error(String msg) {
        return new R().setCode(FAILED).setMsg(msg);
    }

    public R setCode(int code) {
        super.put(CODE_TAG, code);
        return this;
    }

    public R setData(Object data) {
        super.put(DATA_TAG, data);
        return this;
    }
    public R setMsg(String msg) {
        super.put(MSG_TAG, msg);
        return this;
    }
}
